import aepApiRequest from '../utils/aepApiRequest';

interface EmergencyContact {
  id: number;
  mobile: string;
  nickname: string;
  mac: string;
  productKey: string;
}

export async function fetchDeviceEmergencyContacts(mac: string, pk: string) {
  return aepApiRequest<EmergencyContact[]>(`app/smart_home/homes/singleDeviceAlarmMobileList?mac=${mac}&productKey=${pk}`, {
    method: 'GET',
  });
}

export async function createDeviceEmergencyContact(body: Omit<EmergencyContact, 'id'>) {
  return aepApiRequest(
    `/app/smart_home/homes/addSingleDeviceAlarmMobile`,
    {
      method: 'POST',
      body: {
        ...body,
        areaCode: '+86'
      }
    },
  )
}

export async function removeDeviceEmergencyContact(id: number) {
  return aepApiRequest(
    `/app/smart_home/homes/delSingleDeviceAlarmMobile`,
    { method: 'POST', body: [id] },
  )
}
